﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using WuDada.Core.Auth;
using WuDada.Core.Auth.Service;
using WuDada.Core.Auth.Domain;
using WuDada.Core.Auth.Container;
using WuDada.Core.Post.Domain;
using WuDada.Core.Post;
using WuDada.Core.Post.Service;
using WuDada.Core.SystemApplications.Domain;
using WuDada.Core.SystemApplications;
using WuDada.Core.SystemApplications.Service;
using System.Globalization;
using WuDada.Core.Generic.Mail;
using WuDada.Core.Post.DTO;
using WuDada.Core.Post.DTOConverter;
using WuDada.Core.Generic.Util;
using WuDada.Provider.ResourceHandle;
using WuDada.Provider.ResourceHandle.Service;
using WuDada.Provider.ResourceHandle.Domain;
using System.IO;
using WuDada.Core.Member.Domain;
using WuDada.Core.Member.Service;
using WuDada.Core.Member;

namespace GalaxyClinic.Test.Service
{
    [TestFixture]
    public class InitWebDataService
    {
        private AuthFactory m_AuthFactory { get; set; }
        private PostFactory m_PostFactory { get; set; }
        private SystemFactory m_SystemFactory { get; set; }
        private StorageFactory m_StorageFactory { get; set; }
        private IAuthService m_AuthService { get; set; }
        private IPostService m_PostService { get; set; }
        private ITemplateService m_TemplateService { get; set; }
        private ISystemService m_SystemService { get; set; }
        private IMessageService m_MessageService { get; set; }
        private IStorageFileService m_StorageFileService { get; set; }
        private MemberFactory m_MemberFactory { get; set; }
        private IMemberService m_MemberService { get; set; }
        private IQuestionService m_QuestionService { get; set; }
        private IAnswerService m_AnswerService { get; set; }

        [TestFixtureSetUp]
        public void TestCaseInit()
        {
            m_AuthFactory = new AuthFactory();
            m_PostFactory = new PostFactory();
            m_SystemFactory = new SystemFactory();
            m_StorageFactory = new StorageFactory();
            m_MemberFactory = new MemberFactory();
            m_AuthService = m_AuthFactory.GetAuthService();
            m_PostService = m_PostFactory.GetPostService();
            m_TemplateService = m_SystemFactory.GetTemplateService();
            m_SystemService = m_SystemFactory.GetSystemService();
            m_MessageService = m_PostFactory.GetMessageService();
            m_StorageFileService = m_StorageFactory.GetStorageFileService();
            m_MemberService = m_MemberFactory.GetMemberService();
            m_QuestionService = m_PostFactory.GetQuestionService();
            m_AnswerService = m_PostFactory.GetAnswerService();
        }

        [Test]
        public void InitWebData()
        {
            InitMenu();
            InitLoginRoleAndUser();
            InitNode();
            InitSystemParam();
        }

        [Test]
        public void Test_PostSearch()
        {
            string key = "ggg+odu";
            string[] keys = key.Split('+');
            string[] columns = new string[] { "Title", "TitleENG", "HtmlContent", "HtmlContentENG", "HtmlContent2", "HtmlContent2ENG" };

            StringBuilder sbHql = new StringBuilder();
            //sbHql.Append("WHERE ParentPost.PostId = 4 ");
            sbHql.Append(string.Format(@"WHERE Flag = {0} 
AND ShowDate <= '{1}' AND CloseDate >= '{1}'
AND ParentPost.ParentPost.ParentPost.PostId = {2} 
AND {3} 
ORDER BY SortNo "
                , 1, DateTime.Today.ToShortDateString(), 4
                , ConvertUtil.ConvetSqlLikeStr(keys, columns, "OR")));
            //, ConvertUtil.ConvetSqlLikeStr(keys, columns, "OR")
            //"Title like '%odu%' "
            IList<PostVO> postList = m_PostService.SearchPostByWhere(sbHql.ToString());
            Console.Write("postList count =" + postList.Count);
        }

        [Test]
        public void Test_UserMenuFuncContainer()
        {
            //清除快取
            UserMenuFuncContainer.GetInstance().ReloadAllMenu();

            UserMenuFuncContainer.GetInstance().GetUser("admin");
            UserMenuFuncContainer.GetInstance().GetUser("admin");
        }

        [Test]
        public void Test_InitContactorMail()
        {
            string classify = "聯絡我們收件者";
            ItemParamVO contactor = new ItemParamVO(classify, "吳信達", "dada2cindy@hotmail.com", false);
            m_SystemService.CreateItemParam(contactor);

            ItemParamVO contactor2 = new ItemParamVO(classify, "王小小", "dada@pro2e.com.tw", false);
            m_SystemService.CreateItemParam(contactor2);

            IList<ItemParamVO> contactorList = m_SystemService.GetAllItemParamByNoDel(classify);
            Console.WriteLine("contactorList count =" + contactorList.Count);
        }

        [Test]
        public void Test_SendMessageMail()
        {
            //建立一篇訊息
            MessageVO messageVO = new MessageVO();
            messageVO.Content = "意見";
            messageVO.CreateName = "張大保";
            messageVO.EMail = "dada2338@yahoo.com.tw";
            messageVO.Fax = "23223333";
            messageVO.Phone = "22234563";
            messageVO.Mobile = "0912333444";
            messageVO.CreatedDate = DateTime.Now;
            messageVO.CreateIP = "127.0.0.1";

            messageVO = m_MessageService.CreateMessage(messageVO);

            string classify = "聯絡我們收件者";
            IList<ItemParamVO> contactorList = m_SystemService.GetAllItemParamByNoDel(classify);

            if (contactorList != null && contactorList.Count > 0)
            {
                SystemParamVO mailVO = m_SystemService.GetSystemParamByRoot();
                MailService mailService = new MailService(mailVO.MailSmtp, int.Parse(mailVO.MailPort), mailVO.EnableSSL, mailVO.Account, mailVO.Password);

                StringBuilder sbMailList = new StringBuilder();
                foreach (ItemParamVO contactor in contactorList)
                {
                    sbMailList.Append(string.Format("{0};", contactor.Value));
                }

                string mailTitle = string.Format("收到一封由【{0}】從產基會網站提出的意見信。", messageVO.CreateName);
                string mailContent = GenMailContent(messageVO);

                mailService.SendMail(mailVO.SendEmail, sbMailList.ToString(), mailTitle, mailContent);
            }
        }

        private string GenMailContent(MessageVO messageVO)
        {
            StringBuilder sbContent = new StringBuilder();

            sbContent.Append(string.Format("時　　間：{0}<br />", messageVO.CreatedDate.Value.ToString()));
            sbContent.Append(string.Format("姓　　名：{0}<br />", messageVO.CreateName));
            sbContent.Append(string.Format("電　　話：{0}<br />", messageVO.Phone));
            sbContent.Append(string.Format("手　　機：{0}<br />", messageVO.Mobile));
            sbContent.Append(string.Format("傳　　真：{0}<br />", messageVO.Fax));
            sbContent.Append(string.Format("電子信箱：{0}<br />", messageVO.EMail));
            sbContent.Append(string.Format("意　　見：{0}<br />", messageVO.Content.Replace("\n", "<br />")));

            return sbContent.ToString();
        }

        [Test]
        public void TestCreateQuestion()
        {
            //初階培訓課程
            int nodeId = 36;
            NodeVO nodeVO = m_PostService.GetNodeById(nodeId);

            //測試建立超過20筆問題的課程

            PostVO postVO = CreatePost("Test認識輕度失智症", nodeVO, 100, "", "G_kiss.wmv");
            CreateQuestionList(postVO, 50);                       

            //測試建立低於20筆問題的課程
            PostVO postVO2 = CreatePost("Test輕度失智健康促進服務理念與實務", nodeVO, 101);
            CreateQuestionList(postVO2, 17);


            //建立會員並且取得空白的問卷
            MemberVO memberVO = CreateMember("測試帳號1", "test1", true);
            AnswerVO answerVO1_1 = m_AnswerService.CreateEmptyAnswer(postVO.PostId, 20, memberVO);
            AnswerVO answerVO1_2 = m_AnswerService.CreateEmptyAnswer(postVO2.PostId, 20, memberVO);

            MemberVO memberVO2 = CreateMember("測試帳號2", "test2", false);
            AnswerVO answerVO2_1 = m_AnswerService.CreateEmptyAnswer(postVO.PostId, 20, memberVO);
            AnswerVO answerVO2_2 = m_AnswerService.CreateEmptyAnswer(postVO2.PostId, 20, memberVO);

            MemberVO memberVO3 = CreateMember("測試帳號3", "test3", false);
            AnswerVO answerVO3_1 = m_AnswerService.CreateEmptyAnswer(postVO.PostId, 20, memberVO);
            AnswerVO answerVO3_2 = m_AnswerService.CreateEmptyAnswer(postVO2.PostId, 20, memberVO);

            ////完成問卷
            FinishAnswer(answerVO1_1, true);
            FinishAnswer(answerVO2_1, false);
            FinishAnswer(answerVO3_1, true);
        }

        private void FinishAnswer(AnswerVO answerVO, bool allPass)
        {
            IDictionary<string, string> conditions = new Dictionary<string, string>();
            conditions.Add("AnswerId", answerVO.AnswerId.ToString());
            conditions.Add("Flag", "1");

            IList<AnswerDetailVO> answerDetailList = m_AnswerService.GetAnswerDetailList(conditions);
            if (answerDetailList != null && answerDetailList.Count > 0)
            {
                foreach (AnswerDetailVO answerDetailVO in answerDetailList)
                {
                    if (allPass)
                    {
                        answerDetailVO.UserAnswer = answerDetailVO.CorrectAnswer;
                    }
                    else
                    {
                        answerDetailVO.UserAnswer = answerDetailVO.Option1;
                    }
                    m_AnswerService.UpdateAnswerDetail(answerDetailVO);
                }
            }

            m_AnswerService.UpdateFinishAnswer(answerVO, 60);
        }

        private MemberVO CreateMember(string name, string loginId, bool isAdmin)
        {
            MemberVO memberVO = new MemberVO();
            memberVO.Name = name;
            memberVO.LoginId = loginId;
            memberVO.Password = "1111";
            memberVO.CreatedDate = DateTime.Now;
            memberVO.UpdatedDate = DateTime.Now;
            memberVO.CreateIP = "127.0.0.1";
            memberVO.Status = "1";
            memberVO.IsAdmin = isAdmin;
           
            return m_MemberService.CreateMember(memberVO);
        }

        private void CreateQuestionList(PostVO postVO, int questionNum)
        {
            for (int i = 1; i <= questionNum; i++)
            {
                QuestionVO questionVO = new QuestionVO();

                int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
                array = ShuffleArray(array);

                questionVO.Option1 = "項目" + array[0];
                questionVO.Option2 = "項目" + array[1];
                questionVO.Option3 = "項目" + array[2];
                questionVO.Option4 = "項目" + array[3];
                int correctNum = new Random().Next(0, 3);
                questionVO.CorrectAnswer = "項目" + array[correctNum];

                questionVO.CreatedBy = "admin";
                questionVO.CreatedDate = DateTime.Now;
                questionVO.Flag = 1;
                questionVO.Post = postVO;
                questionVO.Question = "問題" + i;
                questionVO.CanScore = 5;
                questionVO.SortNo = i;
                questionVO.UpdatedBy = "admin";
                questionVO.UpdatedDate = DateTime.Now;
                m_QuestionService.CreateQuestion(questionVO);
            }
        }

        public int[] ShuffleArray(int[] array)
        {
            Random r = new Random();
            for (int i = array.Length; i > 0; i--)
            {
                int j = r.Next(i);
                int k = array[j];
                array[j] = array[i - 1];
                array[i - 1] = k;
            }
            return array;
        }

        [Test]
        public void TestDay()
        {
            TaiwanLunisolarCalendar tlc = new TaiwanLunisolarCalendar();

            int year = tlc.GetYear(DateTime.Now);
            int month = tlc.GetMonth(DateTime.Now);
            int day = tlc.GetDayOfMonth(DateTime.Now);

            string aa = string.Format("{0}/{1}/{2}", year, month, day);
            Console.WriteLine("day = " + aa);

            DateTime date2 = tlc.ToDateTime(year, month, day, 0, 0, 0, 0);
            Console.WriteLine("day2 = " + date2.ToShortDateString());
        }

        [Test]
        public void TestPostVOConverter()
        {
            IList<PostVO> postList = m_PostService.GetPostListByParentPostId(22);

            IList<ReportPostVO> reportList = PostVOConverter.ToDataTransferObjects(postList, 2);
            Console.WriteLine("reportList = " + reportList.Count);

            //IList<ReportPostVO> reportList2 = PostVOConverter.ToDataTransferObjects(postList, 3);
            //Console.WriteLine("reportList2 = " + reportList2.Count);

            //IList<ReportPostVO> reportList3 = PostVOConverter.ToDataTransferObjects(postList, 6);
            //Console.WriteLine("reportList3 = " + reportList3.Count);
        }

        [Test]
        public void TestCurrentTemplate()
        {
            TemplateVO templateVO = m_TemplateService.GetCurrentTemplate(7);
            Console.WriteLine("TestCurrentTemplate = " + templateVO.Name);
        }

        [Test]
        public void TestGetPostListByNodeId()
        {
            int nodeId = 22;

            //搜尋條件
            DateTime? startDate = DateTime.Today;
            string sortField = "ShowDate";
            bool sortDesc = true;
            int pageSize = 2;

            IList<PostVO> postList = m_PostService.GetPostListByNodeId(nodeId, true, startDate, 0, pageSize, sortField, sortDesc);

            int count = postList.Count;
            Console.WriteLine("postList count = " + count);
        }

        [Test]
        public void TestGetStorageDirectory()
        {
            DirectoryInfo di = m_StorageFileService.GetStorageDirectory(FolderType.UPLOAD_FOLDER, true);
            Console.WriteLine("di = " + di.FullName);            
        }

        [Test]
        public void TestCreateStorageFile()
        {
            string sourceFilePath =@"D:\我的case\小布\鋁門窗\SVN上傳\trunk\doc\規格說明書附件.docx";
            FileInfo fileInfo = new FileInfo(sourceFilePath);
            DirectoryInfo dir = m_StorageFileService.GetStorageDirectory(FolderType.UPLOAD_FOLDER, true);
            string newFileName = Guid.NewGuid().ToString() + fileInfo.Extension;
            string destFileName = Path.Combine(dir.FullName, newFileName);
            File.Copy(sourceFilePath, destFileName);

            StorageFileVO storageFileVO = new StorageFileVO();
            storageFileVO.SourceUri = fileInfo.FullName;
            storageFileVO.CurrentPath = destFileName;
            storageFileVO.FileName = fileInfo.Name;
            storageFileVO.DisplayName = fileInfo.Name;
            storageFileVO.FileSize = fileInfo.Length;
            storageFileVO.SourceType = StorageFileVO.StorageSourceType.Post;
            storageFileVO.SourceId = 1;
            storageFileVO.CreatedBy = "admin";
            storageFileVO.UpdatedBy = "admin";
            storageFileVO.CreatedDate = DateTime.Now;
            storageFileVO.UpdatedDate = DateTime.Now;
            m_StorageFileService.CreateStorageFile(storageFileVO);
        }

        [Test]
        public void Test_Member()
        {
            IDictionary<string, string> conditions = new Dictionary<string, string>();

            int memberCount = m_MemberService.GetMemberCount(conditions);
            IList<MemberVO> memberList = m_MemberService.GetMemberList(conditions);
            Assert.AreEqual(memberCount, memberList.Count);
        }

        private void InitMenu()
        {
            MenuFuncVO parentMenu1 = CreateParentMenu("關於失智症管理", 1000);
            CreateSubMenu("關於我們", parentMenu1, 1001, "admin/UC01/0101.aspx");
            CreateSubMenu("緣起及沿革", parentMenu1, 1002, "admin/UC01/0102.aspx");
            CreateSubMenu("各國發展", parentMenu1, 1003, "admin/UC01/0103.aspx");
            CreateSubMenu("相關政策", parentMenu1, 1004, "admin/UC01/0104.aspx");
            CreateSubMenu("服務內容及現況", parentMenu1, 1005, "admin/UC01/0105.aspx");

            ////這要做一般清單 可查詢名稱, 地區查詢, Detail有 地區+縣市連動ddl (0211預留給做分類用的)
            MenuFuncVO parentMenu2 = CreateParentMenu("各地學堂訊息管理", 2000);
            CreateSubMenu("各地學堂訊息列表", parentMenu2, 2001, "admin/UC02/0212.aspx");

            MenuFuncVO parentMenu51 = CreateParentMenu("培力資源", 3000);
            CreateSubMenu("實體培訓課程列表", parentMenu51, 3001, "admin/UC05/0511.aspx");

            MenuFuncVO parentMenu8 = CreateParentMenu("會員管理", 4000);
            CreateSubMenu("會員列表", parentMenu8, 4001, "admin/UC08/0811.aspx"); //裡面可以審核開通, 登錄學習時數,查詢線上測驗結果

            MenuFuncVO parentMenu52 = CreateParentMenu("網路學習", 5000);
            CreateSubMenu("初階培訓課程列表", parentMenu52, 5001, "admin/UC08/0821.aspx"); //(list顯示測試人數,及格人數,平均分數), detail裡面要 可以管理題庫
            CreateSubMenu("測驗記錄", parentMenu52, 5001, "admin/UC08/0822.aspx"); //列出測驗者清單資料,可用是否申請跟處理狀態,是否及格查詢
            CreateSubMenu("下載列表", parentMenu52, 5003, "admin/UC05/0521.aspx");

            MenuFuncVO parentMenu12 = CreateParentMenu("加入我們管理", 6000);
            CreateSubMenu("加入我們", parentMenu12, 6001, "admin/UC01/0106.aspx");
            CreateSubMenu("加入我們填寫紀錄", parentMenu12, 6002, "admin/UC02/0221.aspx"); //區間查詢, 處理狀態

            ////討論區 會員工能裡可以設定會員是否為管理員，前台可以直接管理刪除

            MenuFuncVO parentMenu6 = CreateParentMenu("聯絡我們管理", 7000);
            CreateSubMenu("聯絡我們紀錄", parentMenu6, 7001, "admin/UC02/0222.aspx"); //用新做的加入來改
            CreateSubMenu("收件者信箱設定", parentMenu6, 7002, "admin/UC06/0602.aspx");

            //MenuFuncVO parentMenu3 = CreateParentMenu("活動資訊管理", 5000);
            ////CreateSubMenu("相簿分類", parentMenu3, 3001, "admin/UC03/0302.aspx");
            //MenuFuncVO subMenuFuncVO3_1 = CreateSubMenu("活動列表", parentMenu3, 5002, "admin/UC03/0301.aspx");
            //m_AuthService.AddOtherPath(subMenuFuncVO3_1, "admin/UC03/0301_1.aspx");//相簿圖片管理            

            MenuFuncVO parentMenu30 = CreateParentMenu("個人設定", 99998);
            CreateSubMenu("登入密碼變更", parentMenu30, 1, "admin/UC30/3001Personal.aspx");

            MenuFuncVO parentMenu14 = CreateParentMenu("權限管理", 99999);
            CreateSubMenu("帳號管理", parentMenu14, 1, "admin/UC14/UserAdd.aspx");
            CreateSubMenu("群組管理", parentMenu14, 2, "admin/UC14/RoleAdd.aspx");
            CreateSubMenu("帳號群組設定", parentMenu14, 3, "admin/UC14/UserRoleSet.aspx");
            CreateSubMenu("群組權限設定", parentMenu14, 4, "admin/UC14/RoleFuncSet.aspx");
            CreateSubMenu("使用紀錄", parentMenu14, 5, "admin/UC14/QueryLog.aspx");
        }

        private void InitLoginRoleAndUser()
        {
            //建立後台角色
            LoginRoleVO loginRoleVO = new LoginRoleVO("系統管理員");
            loginRoleVO.MenuFuncList = m_AuthService.GetNotTopMenuFunc(); //角色功能權限
            m_AuthService.CreateLoginRole(loginRoleVO);

            LoginUserVO loginUserVO = new LoginUserVO();
            loginUserVO.UserId = "admin";
            loginUserVO.Password = "1234";
            loginUserVO.FullNameInChinese = "系統管理者";
            loginUserVO.FullNameInEnglish = "Administrator";
            loginUserVO.LoginRoleList = new List<LoginRoleVO>();
            loginUserVO.LoginRoleList.Add(loginRoleVO);
            loginUserVO.CreateDate = DateTime.Now;
            m_AuthService.CreateLoginUser(loginUserVO);
        }

        private void InitNode()
        {
            NodeVO rootNodeVO = CreateNode("Root", null, 0);
            NodeVO nodeVO1 = CreateNode("關於失智症管理", rootNodeVO, 1);
            CreatePost("關於我們", nodeVO1, 1);
            CreatePost("緣起及沿革", nodeVO1, 2);
            CreatePost("各國發展", nodeVO1, 3);
            CreatePost("相關政策", nodeVO1, 4);
            CreatePost("服務內容及現況", nodeVO1, 5);

            NodeVO nodeVO2 = CreateNode("各地學堂訊息管理", rootNodeVO, 2);
            NodeVO nodeVO21 = CreateNode("北區", nodeVO2, 1);
            NodeVO nodeVO22 = CreateNode("中區", nodeVO2, 2);
            NodeVO nodeVO23 = CreateNode("南區", nodeVO2, 3);
            NodeVO nodeVO24 = CreateNode("東區", nodeVO2, 4);
            NodeVO nodeVO25 = CreateNode("離島", nodeVO2, 5);

            CreateNode("台北市", nodeVO21, 1);
            CreateNode("新北市", nodeVO21, 2);
            CreateNode("基隆市", nodeVO21, 3);
            CreateNode("宜蘭縣", nodeVO21, 4);
            CreateNode("桃園縣", nodeVO21, 5);
            CreateNode("新竹縣市", nodeVO21, 6);

            CreateNode("苗栗縣", nodeVO22, 1);
            CreateNode("台中市", nodeVO22, 2);
            CreateNode("彰化縣", nodeVO22, 3);
            CreateNode("雲林縣", nodeVO22, 4);
            CreateNode("南投縣", nodeVO22, 5);

            CreateNode("嘉義縣市", nodeVO23, 1);
            CreateNode("台南市", nodeVO23, 2);
            CreateNode("高雄市", nodeVO23, 3);
            CreateNode("屏東縣", nodeVO23, 4);

            CreateNode("花蓮縣", nodeVO24, 1);
            CreateNode("台東縣", nodeVO24, 2);

            CreateNode("連江(馬祖)", nodeVO25, 1);
            CreateNode("綠島", nodeVO25, 2);
            CreateNode("蘭嶼", nodeVO25, 3);
            CreateNode("金門縣", nodeVO25, 4);
            CreateNode("澎湖縣", nodeVO25, 5);

            NodeVO nodeVO3 = CreateNode("培力資源", rootNodeVO, 3);
            NodeVO nodeVO31 = CreateNode("實體培訓課程", nodeVO3, 1);
            CreatePost("初階培訓", nodeVO31, 1, string.Empty, string.Empty);
            CreatePost("懷舊工作坊", nodeVO31, 2, string.Empty, string.Empty);
            CreatePost("認知工作坊", nodeVO31, 3, string.Empty, string.Empty);
            CreatePost("音樂工作坊", nodeVO31, 4, string.Empty, string.Empty);
            CreatePost("運動工作坊", nodeVO31, 5, string.Empty, string.Empty);
            CreatePost("藝術工作坊", nodeVO31, 6, string.Empty, string.Empty);
            CreatePost("見習", nodeVO31, 7, string.Empty, string.Empty);
            CreatePost("團體督導", nodeVO31, 8, string.Empty, string.Empty);
            CreatePost("其他", nodeVO31, 9, string.Empty, string.Empty);

            CreateNode("品質專業指標", nodeVO3, 2);
            CreateNode("學習時數", nodeVO3, 3);

            NodeVO nodeVO4 = CreateNode("網路學習", rootNodeVO, 4);
            NodeVO nodeVO41 = CreateNode("初階培訓課程", nodeVO4, 1);
            CreatePost("認識輕度失智症", nodeVO41, 1, string.Empty, string.Empty);
            CreatePost("輕度失智健康促進服務理念與實務", nodeVO41, 2, string.Empty, string.Empty);
            PostVO post = CreatePost("失智之認知功能評估", nodeVO41, 3, string.Empty, string.Empty);
            post.Type = 1; ////限實體學習
            m_PostService.UpdatePost(post);
            CreatePost("失智症患者及家屬心理社會反應及調適", nodeVO41, 4, string.Empty, string.Empty);
            CreatePost("失智症患者及家屬支持服務及團體帶領", nodeVO41, 5, string.Empty, string.Empty);
            CreatePost("失智症社會資源", nodeVO41, 6, string.Empty, string.Empty);
            CreatePost("輕度失智老人團體帶領實務", nodeVO41, 7, string.Empty, string.Empty);
            CreatePost("音樂治療團體", nodeVO41, 8, string.Empty, string.Empty);
            CreatePost("懷舊治療團體", nodeVO41, 9, string.Empty, string.Empty);
            CreatePost("藝術創作團體", nodeVO41, 10, string.Empty, string.Empty);
            CreatePost("認知活動團體", nodeVO41, 11, string.Empty, string.Empty);
            CreatePost("其他", nodeVO41, 12, string.Empty, string.Empty);
            NodeVO nodeVO42 = CreateNode("下載", nodeVO4, 1);


            NodeVO nodeVO5 = CreateNode("加入我們", rootNodeVO, 5);
            nodeVO5.HtmlContent = "有意願合作者，請填寫詳細資訊，本會將與您洽談合作事宜。請洽本會專案負責人，陳巧宜社工專員。電話：02-3365-2826#15 ";
            m_PostService.UpdateNode(nodeVO5);
            NodeVO nodeVO51 = CreateNode("標準合作模式", nodeVO5, 1);

            NodeVO nodeVO6 = CreateNode("討論區", rootNodeVO, 6);
            NodeVO nodeVO61 = CreateNode("合作單位討論區", nodeVO6, 1);

            NodeVO nodeVO7 = CreateNode("聯絡我們", rootNodeVO, 7);

            InitCity(CreateNode("縣市地區", rootNodeVO, 8));

            NodeVO nodeVO52 = CreateNode("其他合作模式", nodeVO5, 2);
        }

        private void InitCity(NodeVO rootNodeVO)
        {
            //建立縣市
            NodeVO city1 = CreateNode("台北市", rootNodeVO, 1);
            CreateNode("中正區", city1, 1, "100");
            CreateNode("大同區", city1, 2, "103");
            CreateNode("中山區", city1, 3, "104");
            CreateNode("松山區", city1, 4, "105");
            CreateNode("大安區", city1, 5, "106");
            CreateNode("萬華區", city1, 6, "108");
            CreateNode("信義區", city1, 7, "110");
            CreateNode("士林區", city1, 8, "111");
            CreateNode("北投區", city1, 9, "112");
            CreateNode("內湖區", city1, 10, "114");
            CreateNode("南港區", city1, 11, "115");
            CreateNode("文山區", city1, 12, "116");

            NodeVO city2 = CreateNode("基隆市", rootNodeVO, 2);
            CreateNode("仁愛區", city2, 1, "200");
            CreateNode("信義區", city2, 2, "201");
            CreateNode("中正區", city2, 3, "202");
            CreateNode("中山區", city2, 4, "203");
            CreateNode("安樂區", city2, 5, "204");
            CreateNode("暖暖區", city2, 6, "205");
            CreateNode("七堵區", city2, 7, "206");

            NodeVO city3 = CreateNode("新北市", rootNodeVO, 3);
            CreateNode("萬里區", city3, 1, "207");
            CreateNode("金山區", city3, 2, "208");
            CreateNode("板橋區", city3, 3, "220");
            CreateNode("汐止區", city3, 4, "221");
            CreateNode("深坑區", city3, 5, "222");
            CreateNode("石碇區", city3, 6, "223");
            CreateNode("瑞芳區", city3, 7, "224");
            CreateNode("平溪區", city3, 8, "226");
            CreateNode("雙溪區", city3, 9, "227");
            CreateNode("貢寮區", city3, 10, "228");
            CreateNode("新店區", city3, 11, "231");
            CreateNode("坪林區", city3, 12, "232");
            CreateNode("烏來區", city3, 13, "233");
            CreateNode("永和區", city3, 14, "234");
            CreateNode("中和區", city3, 15, "235");
            CreateNode("土城區", city3, 16, "236");
            CreateNode("三峽區", city3, 17, "237");
            CreateNode("樹林區", city3, 18, "238");
            CreateNode("鶯歌區", city3, 19, "239");
            CreateNode("三重區", city3, 20, "241");
            CreateNode("新莊區", city3, 21, "242");
            CreateNode("泰山區", city3, 22, "243");
            CreateNode("林口區", city3, 23, "244");
            CreateNode("蘆洲區", city3, 24, "247");
            CreateNode("五股區", city3, 25, "248");
            CreateNode("八里區", city3, 26, "249");
            CreateNode("淡水區", city3, 27, "251");
            CreateNode("三芝區", city3, 28, "252");
            CreateNode("石門區", city3, 29, "253");

            NodeVO city4 = CreateNode("連江縣", rootNodeVO, 4);
            CreateNode("南竿鄉", city4, 1, "209");
            CreateNode("北竿鄉", city4, 2, "210");
            CreateNode("莒光鄉", city4, 3, "211");
            CreateNode("東引鄉", city4, 4, "212");

            NodeVO city5 = CreateNode("宜蘭縣", rootNodeVO, 5);
            CreateNode("宜蘭市", city5, 1, "260");
            CreateNode("頭城鎮", city5, 2, "261");
            CreateNode("礁溪鄉", city5, 3, "262");
            CreateNode("壯圍鄉", city5, 4, "263");
            CreateNode("員山鄉", city5, 5, "264");
            CreateNode("羅東鎮", city5, 6, "265");
            CreateNode("三星鄉", city5, 7, "266");
            CreateNode("大同鄉", city5, 8, "267");
            CreateNode("五結鄉", city5, 9, "268");
            CreateNode("冬山鄉", city5, 10, "269");
            CreateNode("蘇澳鎮", city5, 11, "270");
            CreateNode("南澳鄉", city5, 12, "272");
            CreateNode("釣魚台", city5, 13, "290");

            NodeVO city6 = CreateNode("新竹市", rootNodeVO, 6);
            CreateNode("東區", city6, 1, "300");
            CreateNode("北區", city6, 2, "300");
            CreateNode("香山區", city6, 3, "300");

            NodeVO city7 = CreateNode("新竹縣", rootNodeVO, 7);
            CreateNode("竹北市", city7, 1, "302");
            CreateNode("湖口鄉", city7, 2, "303");
            CreateNode("新豐鄉", city7, 3, "304");
            CreateNode("新埔鎮", city7, 4, "305");
            CreateNode("關西鎮", city7, 5, "306");
            CreateNode("芎林鄉", city7, 6, "307");
            CreateNode("寶山鄉", city7, 7, "308");
            CreateNode("竹東鎮", city7, 8, "310");
            CreateNode("五峰鄉", city7, 9, "311");
            CreateNode("橫山鄉", city7, 10, "312");
            CreateNode("尖石鄉", city7, 11, "313");
            CreateNode("北埔鄉", city7, 12, "314");
            CreateNode("峨眉鄉", city7, 13, "315");

            NodeVO city8 = CreateNode("桃園縣", rootNodeVO, 8);
            CreateNode("中壢市", city8, 1, "320");
            CreateNode("平鎮市", city8, 2, "324");
            CreateNode("龍潭鄉", city8, 3, "325");
            CreateNode("楊梅市", city8, 4, "326");
            CreateNode("新屋鄉", city8, 5, "327");
            CreateNode("觀音鄉", city8, 6, "328");
            CreateNode("桃園市", city8, 7, "330");
            CreateNode("龜山鄉", city8, 8, "333");
            CreateNode("八德市", city8, 9, "334");
            CreateNode("大溪鎮", city8, 10, "345");
            CreateNode("復興鄉", city8, 11, "336");
            CreateNode("大園鄉", city8, 12, "337");
            CreateNode("蘆竹鄉", city8, 13, "338");

            NodeVO city9 = CreateNode("苗栗縣", rootNodeVO, 9);
            CreateNode("竹南鎮", city9, 1, "350");
            CreateNode("頭份鎮", city9, 2, "351");
            CreateNode("三灣鄉", city9, 3, "352");
            CreateNode("南庄鄉", city9, 4, "353");
            CreateNode("獅潭鄉", city9, 5, "354");
            CreateNode("後龍鎮", city9, 6, "356");
            CreateNode("通霄鎮", city9, 7, "357");
            CreateNode("苑裡鎮", city9, 8, "358");
            CreateNode("苗栗市", city9, 9, "360");
            CreateNode("造橋鄉", city9, 10, "361");
            CreateNode("頭屋鄉", city9, 11, "362");
            CreateNode("公館鄉", city9, 12, "363");
            CreateNode("大湖鄉", city9, 13, "364");
            CreateNode("泰安鄉", city9, 14, "365");
            CreateNode("銅鑼鄉", city9, 15, "366");
            CreateNode("三義鄉", city9, 16, "367");
            CreateNode("西湖鄉", city9, 17, "368");
            CreateNode("卓蘭鎮", city9, 18, "369");

            NodeVO city10 = CreateNode("台中市", rootNodeVO, 10);
            CreateNode("中區", city10, 1, "400");
            CreateNode("東區", city10, 2, "401");
            CreateNode("南區", city10, 3, "402");
            CreateNode("西區", city10, 4, "403");
            CreateNode("北區", city10, 5, "404");
            CreateNode("北屯區", city10, 6, "406");
            CreateNode("西屯區", city10, 7, "407");
            CreateNode("南屯區", city10, 8, "408");
            CreateNode("太平區", city10, 9, "411");
            CreateNode("大里區", city10, 10, "412");
            CreateNode("霧峰區", city10, 11, "413");
            CreateNode("烏日區", city10, 12, "414");
            CreateNode("豐原區", city10, 13, "420");
            CreateNode("后里區", city10, 14, "421");
            CreateNode("石岡區", city10, 15, "422");
            CreateNode("東勢區", city10, 16, "423");
            CreateNode("和平區", city10, 17, "424");
            CreateNode("新社區", city10, 18, "426");
            CreateNode("潭子區", city10, 19, "427");
            CreateNode("大雅區", city10, 20, "428");
            CreateNode("神岡區", city10, 21, "429");
            CreateNode("大肚區", city10, 22, "432");
            CreateNode("沙鹿區", city10, 23, "433");
            CreateNode("龍井區", city10, 24, "434");
            CreateNode("梧棲區", city10, 25, "435");
            CreateNode("清水區", city10, 26, "436");
            CreateNode("大甲區", city10, 27, "437");
            CreateNode("外埔區", city10, 28, "438");
            CreateNode("大安區", city10, 29, "439");

            NodeVO city11 = CreateNode("彰化縣", rootNodeVO, 11);
            CreateNode("彰化市", city11, 1, "500");
            CreateNode("芬園鄉", city11, 2, "502");
            CreateNode("花壇鄉", city11, 3, "503");
            CreateNode("秀水鄉", city11, 4, "504");
            CreateNode("鹿港鎮", city11, 5, "505");
            CreateNode("福興鄉", city11, 6, "506");
            CreateNode("線西鄉", city11, 7, "507");
            CreateNode("和美鎮", city11, 8, "508");
            CreateNode("伸港鄉", city11, 9, "509");
            CreateNode("員林鎮", city11, 10, "510");
            CreateNode("社頭鄉", city11, 11, "511");
            CreateNode("永靖鄉", city11, 12, "512");
            CreateNode("埔心鄉", city11, 13, "513");
            CreateNode("溪湖鎮", city11, 14, "514");
            CreateNode("大村鄉", city11, 15, "515");
            CreateNode("埔鹽鄉", city11, 16, "516");
            CreateNode("田中鎮", city11, 17, "520");
            CreateNode("北斗鎮", city11, 18, "521");
            CreateNode("田尾鄉", city11, 19, "522");
            CreateNode("埤頭鄉", city11, 20, "523");
            CreateNode("溪州鄉", city11, 21, "524");
            CreateNode("竹塘鄉", city11, 22, "525");
            CreateNode("二林鎮", city11, 23, "526");
            CreateNode("大城鄉", city11, 24, "527");
            CreateNode("芳苑鄉", city11, 25, "528");
            CreateNode("二水鄉", city11, 26, "530");

            NodeVO city12 = CreateNode("南投縣", rootNodeVO, 12);
            CreateNode("南投市", city12, 1, "540");
            CreateNode("中寮鄉", city12, 2, "541");
            CreateNode("草屯鎮", city12, 3, "542");
            CreateNode("國姓鄉", city12, 4, "544");
            CreateNode("埔里鎮", city12, 5, "545");
            CreateNode("仁愛鄉", city12, 6, "546");
            CreateNode("名間鄉", city12, 7, "551");
            CreateNode("集集鎮", city12, 8, "552");
            CreateNode("水里鄉", city12, 9, "553");
            CreateNode("魚池鄉", city12, 10, "555");
            CreateNode("信義鄉", city12, 11, "556");
            CreateNode("竹山鎮", city12, 12, "557");
            CreateNode("鹿谷鄉", city12, 13, "558");

            NodeVO city13 = CreateNode("嘉義市", rootNodeVO, 13);
            CreateNode("嘉義市", city13, 1, "600");

            NodeVO city14 = CreateNode("嘉義縣", rootNodeVO, 14);
            CreateNode("番路鄉", city14, 1, "600");
            CreateNode("梅山鄉", city14, 2, "603");
            CreateNode("竹崎鄉", city14, 3, "604");
            CreateNode("阿里山鄉", city14, 4, "605");
            CreateNode("中埔鄉", city14, 5, "606");
            CreateNode("大埔鄉", city14, 6, "607");
            CreateNode("水上鄉", city14, 7, "608");
            CreateNode("鹿草鄉", city14, 8, "611");
            CreateNode("太保市", city14, 9, "612");
            CreateNode("朴子市", city14, 10, "613");
            CreateNode("東石鄉", city14, 11, "614");
            CreateNode("六腳鄉", city14, 12, "615");
            CreateNode("新港鄉", city14, 13, "616");
            CreateNode("民雄鄉", city14, 14, "621");
            CreateNode("大林鎮", city14, 15, "622");
            CreateNode("溪口鄉", city14, 16, "623");
            CreateNode("義竹鄉", city14, 17, "624");
            CreateNode("布袋鎮", city14, 18, "625");

            NodeVO city15 = CreateNode("雲林縣", rootNodeVO, 15);
            CreateNode("斗南鎮", city15, 1, "630");
            CreateNode("大埤鄉", city15, 2, "631");
            CreateNode("虎尾鎮", city15, 3, "632");
            CreateNode("土庫鎮", city15, 4, "633");
            CreateNode("東勢鄉", city15, 5, "635");
            CreateNode("褒忠鄉", city15, 6, "634");
            CreateNode("台西鄉", city15, 7, "636");
            CreateNode("崙背鄉", city15, 8, "637");
            CreateNode("麥寮鄉", city15, 9, "638");
            CreateNode("斗六市", city15, 10, "640");
            CreateNode("林內鄉", city15, 11, "643");
            CreateNode("古坑鄉", city15, 12, "646");
            CreateNode("莿桐鄉", city15, 13, "647");
            CreateNode("西螺鎮", city15, 14, "648");
            CreateNode("二崙鄉", city15, 15, "649");
            CreateNode("北港鎮", city15, 16, "651");
            CreateNode("水林鄉", city15, 17, "652");
            CreateNode("口湖鄉", city15, 18, "653");
            CreateNode("四湖鄉", city15, 19, "654");
            CreateNode("元長鄉", city15, 20, "655");

            NodeVO city16 = CreateNode("台南市", rootNodeVO, 16);
            CreateNode("中西區", city16, 1, "700");
            CreateNode("東區", city16, 2, "701");
            CreateNode("南區", city16, 3, "702");
            CreateNode("北區", city16, 4, "704");
            CreateNode("安平區", city16, 5, "708");
            CreateNode("安南區", city16, 6, "709");
            CreateNode("永康區", city16, 7, "710");
            CreateNode("歸仁區", city16, 8, "711");
            CreateNode("新化區", city16, 9, "712");
            CreateNode("左鎮區", city16, 10, "713");
            CreateNode("玉井區", city16, 11, "714");
            CreateNode("楠西區", city16, 12, "715");
            CreateNode("仁德區", city16, 13, "717");
            CreateNode("關廟區", city16, 14, "718");
            CreateNode("南化區", city16, 15, "716");
            CreateNode("龍崎區", city16, 16, "719");
            CreateNode("官田區", city16, 17, "720");
            CreateNode("麻豆區", city16, 18, "721");
            CreateNode("佳里區", city16, 19, "722");
            CreateNode("西港區", city16, 20, "723");
            CreateNode("七股區", city16, 21, "724");
            CreateNode("將軍區", city16, 22, "725");
            CreateNode("學甲區", city16, 23, "726");
            CreateNode("北門區", city16, 24, "727");
            CreateNode("新營區", city16, 25, "730");
            CreateNode("後壁區", city16, 26, "731");
            CreateNode("白河區", city16, 27, "732");
            CreateNode("東山區", city16, 28, "733");
            CreateNode("六甲區", city16, 29, "734");
            CreateNode("下營區", city16, 30, "735");
            CreateNode("柳營區", city16, 31, "736");
            CreateNode("鹽水區", city16, 32, "737");
            CreateNode("善化區", city16, 33, "741");
            CreateNode("大內區", city16, 34, "742");
            CreateNode("新市區", city16, 35, "744");
            CreateNode("安定區", city16, 36, "745");
            CreateNode("山上區", city16, 37, "743");

            NodeVO city17 = CreateNode("高雄市", rootNodeVO, 17);
            CreateNode("新興區", city17, 1, "800");
            CreateNode("前金區", city17, 2, "801");
            CreateNode("苓雅區", city17, 3, "802");
            CreateNode("鹽埕區", city17, 4, "803");
            CreateNode("鼓山區", city17, 5, "804");
            CreateNode("旗津區", city17, 6, "805");
            CreateNode("前鎮區", city17, 7, "806");
            CreateNode("三民區", city17, 8, "807");
            CreateNode("楠梓區", city17, 9, "811");
            CreateNode("小港區", city17, 10, "812");
            CreateNode("左營區", city17, 11, "813");
            CreateNode("仁武區", city17, 12, "814");
            CreateNode("大社區", city17, 13, "815");
            CreateNode("東沙群島", city17, 14, "817");
            CreateNode("岡山區", city17, 15, "820");
            CreateNode("路竹區", city17, 16, "821");
            CreateNode("南沙群島", city17, 17, "819");
            CreateNode("阿蓮區", city17, 18, "822");
            CreateNode("田寮區", city17, 19, "823");
            CreateNode("燕巢區", city17, 20, "824");
            CreateNode("橋頭區", city17, 21, "825");
            CreateNode("梓官區", city17, 22, "826");
            CreateNode("彌陀區", city17, 23, "827");
            CreateNode("湖內區", city17, 24, "829");
            CreateNode("永安區", city17, 25, "828");
            CreateNode("鳳山區", city17, 26, "830");
            CreateNode("大寮區", city17, 27, "831");
            CreateNode("林園區", city17, 28, "832");
            CreateNode("鳥松區", city17, 29, "833");
            CreateNode("大樹區", city17, 30, "840");
            CreateNode("旗山區", city17, 31, "842");
            CreateNode("美濃區", city17, 32, "843");
            CreateNode("六龜區", city17, 33, "844");
            CreateNode("內門區", city17, 34, "845");
            CreateNode("甲仙區", city17, 35, "847");
            CreateNode("杉林區", city17, 36, "846");
            CreateNode("桃源區", city17, 37, "848");
            CreateNode("茄萣區", city17, 38, "852");
            CreateNode("茂林區", city17, 39, "851");
            CreateNode("那瑪夏區", city17, 40, "849");

            NodeVO city18 = CreateNode("澎湖縣", rootNodeVO, 18);
            CreateNode("馬公市", city18, 1, "880");
            CreateNode("西嶼鄉", city18, 2, "881");
            CreateNode("望安鄉", city18, 3, "882");
            CreateNode("湖西鄉", city18, 4, "885");
            CreateNode("七美鄉", city18, 5, "883");
            CreateNode("白沙鄉", city18, 6, "884");

            NodeVO city19 = CreateNode("金門縣", rootNodeVO, 19);
            CreateNode("金沙鎮", city19, 1, "890");
            CreateNode("金湖鎮", city19, 2, "891");
            CreateNode("金寧鄉", city19, 3, "892");
            CreateNode("金城鎮", city19, 4, "893");
            CreateNode("烈嶼鄉", city19, 5, "894");
            CreateNode("烏坵鄉", city19, 6, "896");

            NodeVO city20 = CreateNode("高雄市", rootNodeVO, 20);
            CreateNode("屏東市", city20, 1, "900");
            CreateNode("三地門鄉", city20, 2, "901");
            CreateNode("霧台鄉", city20, 3, "902");
            CreateNode("瑪家鄉", city20, 4, "903");
            CreateNode("九如鄉", city20, 5, "904");
            CreateNode("里港鄉", city20, 6, "905");
            CreateNode("高樹鄉", city20, 7, "906");
            CreateNode("鹽埔鄉", city20, 8, "907");
            CreateNode("長治鄉", city20, 9, "908");
            CreateNode("麟洛鄉", city20, 10, "909");
            CreateNode("竹田鄉", city20, 11, "911");
            CreateNode("內埔鄉", city20, 12, "912");
            CreateNode("萬丹鄉", city20, 13, "913");
            CreateNode("潮州鎮", city20, 14, "920");
            CreateNode("泰武鄉", city20, 15, "921");
            CreateNode("萬巒鄉", city20, 16, "923");
            CreateNode("來義鄉", city20, 17, "922");
            CreateNode("崁頂鄉", city20, 18, "924");
            CreateNode("新埤鄉", city20, 19, "925");
            CreateNode("南州鄉", city20, 20, "926");
            CreateNode("林邊鄉", city20, 21, "927");
            CreateNode("東港鎮", city20, 22, "928");
            CreateNode("琉球鄉", city20, 23, "929");
            CreateNode("佳冬鄉", city20, 24, "931");
            CreateNode("新園鄉", city20, 25, "932");
            CreateNode("枋寮鄉", city20, 26, "940");
            CreateNode("枋山鄉", city20, 27, "941");
            CreateNode("獅子鄉", city20, 28, "943");
            CreateNode("車城鄉", city20, 29, "944");
            CreateNode("牡丹鄉", city20, 30, "945");
            CreateNode("恆春鎮", city20, 31, "946");
            CreateNode("滿州鄉", city20, 32, "947");
            CreateNode("春日鄉", city20, 33, "942");

            NodeVO city21 = CreateNode("台東縣", rootNodeVO, 21);
            CreateNode("台東市", city21, 1, "950");
            CreateNode("綠島鄉", city21, 2, "951");
            CreateNode("蘭嶼鄉", city21, 3, "952");
            CreateNode("卑南鄉", city21, 4, "954");
            CreateNode("鹿野鄉", city21, 5, "955");
            CreateNode("關山鎮", city21, 6, "956");
            CreateNode("海端鄉", city21, 7, "957");
            CreateNode("池上鄉", city21, 8, "958");
            CreateNode("延平鄉", city21, 9, "953");
            CreateNode("東河鄉", city21, 10, "959");
            CreateNode("成功鎮", city21, 11, "961");
            CreateNode("長濱鄉", city21, 12, "962");
            CreateNode("太麻里鄉", city21, 13, "963");
            CreateNode("大武鄉", city21, 14, "965");
            CreateNode("達仁鄉", city21, 15, "966");
            CreateNode("金峰鄉", city21, 16, "964");

            NodeVO city22 = CreateNode("花蓮縣", rootNodeVO, 22);
            CreateNode("花蓮市", city22, 1, "970");
            CreateNode("新城鄉", city22, 2, "971");
            CreateNode("秀林鄉", city22, 3, "972");
            CreateNode("吉安鄉", city22, 4, "973");
            CreateNode("壽豐鄉", city22, 5, "974");
            CreateNode("鳳林鎮", city22, 6, "975");
            CreateNode("光復鄉", city22, 7, "976");
            CreateNode("豐濱鄉", city22, 8, "977");
            CreateNode("瑞穗鄉", city22, 9, "978");
            CreateNode("玉里鎮", city22, 10, "981");
            CreateNode("萬榮鄉", city22, 11, "979");
            CreateNode("富里鄉", city22, 12, "983");
            CreateNode("卓溪鄉", city22, 13, "982");
        }

        private PostVO CreatePost(string title, NodeVO nodeVO, int sort)
        {
            PostVO postVO = new PostVO();
            postVO.Node = nodeVO;
            postVO.Title = title;
            postVO.SortNo = sort;
            postVO.Flag = 1;
            postVO.CreatedBy = "admin";
            postVO.UpdatedBy = "admin";
            postVO.CreatedDate = DateTime.Now;
            postVO.UpdatedDate = DateTime.Now;
            postVO.ShowDate = DateTime.Today;

            return m_PostService.CreatePost(postVO);
        }

        private PostVO CreatePost(string title, NodeVO nodeVO, int sort, string linkUrl, string picFileName)
        {
            PostVO postVO = new PostVO();
            postVO.Node = nodeVO;
            postVO.Title = title;
            postVO.SortNo = sort;
            postVO.Flag = 1;
            postVO.CreatedBy = "admin";
            postVO.UpdatedBy = "admin";
            postVO.CreatedDate = DateTime.Now;
            postVO.UpdatedDate = DateTime.Now;
            postVO.ShowDate = DateTime.Today;
            postVO.LinkUrl = linkUrl;
            postVO.PicFileName = picFileName;

            return m_PostService.CreatePost(postVO);
        }

        private NodeVO CreateNode(string name, NodeVO parentNode, int sort)
        {
            return CreateNode(name, parentNode, sort, string.Empty);
        }

        private NodeVO CreateNode(string name, NodeVO parentNode, int sort, string content)
        {
            NodeVO rootNodeVO = new NodeVO();
            rootNodeVO.Name = name;
            rootNodeVO.ParentNode = parentNode;
            rootNodeVO.SortNo = sort;
            rootNodeVO.Flag = 1;
            rootNodeVO.CreatedBy = "admin";
            rootNodeVO.UpdatedBy = "admin";
            rootNodeVO.CreatedDate = DateTime.Now;
            rootNodeVO.UpdatedDate = DateTime.Now;
            rootNodeVO.HtmlContent = content;

            return m_PostService.CreateNode(rootNodeVO);
        }

        private NodeVO CreateNode(string name, NodeVO parentNode, int sort, NodeVO.UnitType unitType, string filePath)
        {
            NodeVO rootNodeVO = new NodeVO();
            rootNodeVO.Name = name;
            rootNodeVO.ParentNode = parentNode;
            rootNodeVO.SortNo = sort;
            rootNodeVO.Flag = 1;
            rootNodeVO.CreatedBy = "admin";
            rootNodeVO.UpdatedBy = "admin";
            rootNodeVO.CreatedDate = DateTime.Now;
            rootNodeVO.UpdatedDate = DateTime.Now;
            rootNodeVO.UType = unitType;
            rootNodeVO.PicFileName = filePath;

            return m_PostService.CreateNode(rootNodeVO);
        }

        private MenuFuncVO CreateParentMenu(string menuName, int sort)
        {
            MenuFuncVO menuFuncVO = new MenuFuncVO(menuName, null);
            menuFuncVO.ListOrder = sort;

            return m_AuthService.CreateMenuFunc(menuFuncVO);
        }

        private MenuFuncVO CreateSubMenu(string menuName, MenuFuncVO parentMenu, int sort, string path)
        {
            MenuFuncVO menuFuncVO = new MenuFuncVO(menuName, parentMenu);
            menuFuncVO.ListOrder = sort;
            menuFuncVO.MainPath = path;

            return m_AuthService.CreateMenuFunc(menuFuncVO);
        }

        private void InitSystemParam()
        {
            //系統設定
            SystemParamVO systemParamVO = new SystemParamVO();
            //systemParamVO.MailSmtp = "smtp.gmail.com";
            //systemParamVO.Account = "dada2cindy@gmail.com";
            //systemParamVO.SendEmail = "dada2cindy@gmail.com";
            //systemParamVO.MailPort = "587";
            //systemParamVO.EnableSSL = true;
            //systemParamVO.Password = "1234";

            systemParamVO.MailSmtp = "60.248.85.123";
            systemParamVO.Account = "SmtpUser";
            systemParamVO.SendEmail = "test@test.com";
            systemParamVO.MailPort = "25";
            systemParamVO.EnableSSL = false;
            systemParamVO.Password = "abc+1234";

            //systemParamVO.PageTitle = "彼得杜拉克社會企業";
            //systemParamVO.PageKeyWord = "彼得杜拉克社會企業";
            //systemParamVO.PageDescription = "彼得杜拉克社會企業";            

            m_SystemService.CreateSystemParam(systemParamVO);
        }
    }
}
